﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Customer_Profile.Admin
{
    public partial class DataRightModify : System.Web.UI.Page
    {
        protected static int FunctionId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                    FunctionId = Convert.ToInt32(Request.QueryString["ID"].ToString());
                else
                {
                    KVB.Common.JavaScript.ViewMsgGoUrl("MenuManage.aspx", "You Must Select！");
                }
                if (FunctionId != -1)
                {
                    DataSet ds = DataRightDao.getMenuInfo(FunctionId);
                    txtName.Value = ds.Tables[0].Rows[0]["Function_name"].ToString();
                    txtRemark.Value = ds.Tables[0].Rows[0]["Function_Remark"].ToString();
                    txtOrderid.Value = ds.Tables[0].Rows[0]["Order_id"].ToString();
                    if (ds.Tables[0].Rows[0]["lvl_Type"].ToString().Equals("G"))
                    {
                        rType.SelectedIndex = 1;
                    }
                    else
                    {
                        rType.SelectedIndex = 0;
                    }

                    if (ds.Tables[0].Rows[0]["USED_YN"].ToString() == "Y")
                        drpUsed.SelectedIndex = 0;
                    else
                        drpUsed.SelectedIndex = 1;
                }
            }
        }

        protected void ibtnModify_ServerClick(object sender, EventArgs e)
        {
            DataInfoEntity DataCon = new DataInfoEntity();
            DataCon.FunctionId = FunctionId.ToString();
            DataCon.FunctionName = txtName.Value;
            DataCon.Mark = txtRemark.Value;
            DataCon.Orderid = txtOrderid.Value;
            DataCon.Used = drpUsed.SelectedValue.ToString();

            Hashtable htDataInfo = new Hashtable();
            htDataInfo.Add("DataInfo", DataCon);

            try
            {
                bool isSucess = DataRightDao.updateDataInfo(htDataInfo);
                if (isSucess == true)
                {
                    Response.Write("<script language=javascript>alert('Succeed!');</script>");

                    //记录用户操作日志
                    //CVOC.Comm.WriteSystemLog(Session["SS_USER_ID"].ToString(), Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true), "03", Page.Request.UserHostAddress, Page.Request.Path, "菜单修改操作，修改后的菜单名称为：" + txtName.Value);
                }
            }
            catch
            {
                Response.Write("<script language=javascript>alert('Error!');</script>");
            }
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            Response.Redirect("DataAuthorityManage.aspx", true);
        }
    }
}
